package com.sunlong.jiangwei.dao;

import com.sunlong.jiangwei.entity.JwUser;
import com.sunlong.jiangwei.entity.JwUserRole;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
public interface UserMapper extends Mapper<JwUser> {
    @Select("select * from jw_user where type = 0")
    List<JwUser> findAllAdminUser();

    @Select("select * from jw_user where username = #{user} and type = #{type}")
    JwUser selectByUsername(String user, Integer type);

    @Delete("delete from jw_user_role where user_id = #{userId}")
    void deleteUserRoleById(Long userId);

    @Select("select * from jw_user_role where user_id = #{userId}")
    List<JwUserRole> selectUserRoleById(Long userId);

    @Delete("delete from jw_user where user_id = #{userId}")
    void deleteUserById(Long userId);

    @Insert("insert into jw_user_role(user_id,role_id) values(#{userId},#{roleId})")
    void insertUserRole(Long userId,Long roleId);

    @Update("update jw_user_role set role_id = #{roleId} where user_id = #{userId}")
    void updateUserRole(@Param("userId")Long userId,@Param("roleId") Long roleId);

    @Update("update jw_user set password = #{md5Pass} where username = #{username} and type = #{type}")
    void modifyPassword(@Param("username") String username, @Param("md5Pass")String md5Pass, @Param("type") Integer type);
}
